package com.itheima.web.servlet;

import com.itheima.service.CategoryService;
import com.itheima.utils.BeanFactoryUtils;
import com.itheima.web.base.BaseServlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "CategoryServlet" , urlPatterns = "/category")
public class CategoryServlet extends BaseServlet {

    /**
    * 导航条查询所有
    * */
    protected void findAll(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1.获得请求数据
        //2.调用Service查询数据
        CategoryService categoryService = (CategoryService) BeanFactoryUtils.getBean("categoryService");
        //查询所有
        //返回导航条json数据
        String json = categoryService.findJson();

        //3.响应数据(满足一定的格式-json)
        response.getWriter().print(json);
    }
}
